<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>权限管理</title>
<jsp:include page="include.jsp" />
<script type="text/javascript">
	/**
	 *加载树
	 */
	function selectTree() {
		var gardid = $("#selectid").val();
		//
		$('#tt').tree({
			checkbox : true,
			animate : true,
			url : 'allTreeGardAjax.form?gardid=' + gardid,
			onLoadSuccess : function() {
				$('#tt').tree('expandAll');
			}
		});
	};

	/**
	 *得到选择的树包括父节点, tagID=id&tagID=id
	 */
	function getALLSelectChildren() {
		var tagID = "fid="
		var nodes = $('#tt').tree('getChildren',
				$('#tt').tree('getRoots').target);
		var str = '';
		var node;
		for ( var i = 0; i < nodes.length; i++) {
			node = nodes[i];
			if (node.checked) {//选中的节点
				if (str != '')
					str += '&';
				str += tagID + node.id;
			} else {
				if (node.target.children[node.target.childNodes.length - 2].className == 'tree-checkbox tree-checkbox2') {//没有选中的节点(对于树半选中状态)
					if (str != '')
						str += '&';
					str += tagID + node.id;
				}
			}
		}
		return str;
	};

	/**
	 *保存
	 */
	function save() {
		var data = getALLSelectChildren();
		if (data==''){
			$.messager.alert('提示', '至少选择一个功能树');
			return;
		}
		var gardid = $("#selectid").val();
		data += "&gardid=" + gardid;
		$.ajax({
			type : "POST",
			url : "saveAjax.form",
			data : data,
			success : function(msg) {
				$.messager.alert('提示', msg);
			}
		});
	}
</script>
</head>

	
<body class="easyui-layout">  
    <div region="west"  title="用户权限" style="width:150px;">
    			<select id="selectid"  name="用户权限" size="10" style="width: 100% ; height: 100% ;overflow-y:hidden;" onchange="selectTree()" >
					<option value="1">系统维护</option>
					<option value="2">管理员</option>
					<option value="3">普通用户</option>
				</select>
    </div>  
    <div region="center"  title="功能" style="padding:5px;">
    		<ul id="tt"></ul>
    </div>  
    
    <div region="south"   style="height:50px; padding: 10px">
    		<div style="text-align:center;">
    			<input type="button" value="保   存" onclick="save()">
    		</div>
    	
	</div>
    </div>  
</body>  
</div>
</body>
</html>